

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Moe Wang">
  <meta name="keywords" content="">
  
    <meta name="description" content="判断类型&amp;emsp;&amp;emsp;typeof以及返回类型（都是字符串） 扩展&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;如何判断类型?&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;1.typeof&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;2.instanceof&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;3.Object.prototype.toString.call()   &amp;e">
<meta property="og:type" content="article">
<meta property="og:title" content="初入JS（二）">
<meta property="og:url" content="https://moewang0321.github.io/2019/08/05/2019-08-06-%E5%88%9D%E5%85%A5JS%EF%BC%88%E4%BA%8C%EF%BC%89/index.html">
<meta property="og:site_name" content="moe_大杂烩">
<meta property="og:description" content="判断类型&amp;emsp;&amp;emsp;typeof以及返回类型（都是字符串） 扩展&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;如何判断类型?&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;1.typeof&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;2.instanceof&amp;emsp;&amp;emsp;&amp;emsp;&amp;emsp;3.Object.prototype.toString.call()   &amp;e">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://moewang0321.github.io/2019/08/05/images/function.png">
<meta property="og:image" content="https://moewang0321.github.io/2019/08/05/images/3%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6.png">
<meta property="og:image" content="https://moewang0321.github.io/2019/08/05/images/4%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6.png">
<meta property="article:published_time" content="2019-08-05T07:20:31.000Z">
<meta property="article:modified_time" content="2023-02-14T08:02:17.792Z">
<meta property="article:author" content="Moe Wang">
<meta property="article:tag" content="JavaScript">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://moewang0321.github.io/2019/08/05/images/function.png">
  
  
  
  <title>初入JS（二） - moe_大杂烩</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"moewang0321.github.io","root":"/","version":"1.9.4","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 5.4.2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>moe_大杂烩</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="初入JS（二）"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2019-08-05 15:20" pubdate>
          2019年8月5日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          5.1k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          43 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">初入JS（二）</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="判断类型"><a href="#判断类型" class="headerlink" title="判断类型"></a>判断类型</h2><p>&emsp;&emsp;typeof以及返回类型（都是字符串）</p>
<h4 id="扩展"><a href="#扩展" class="headerlink" title="扩展"></a>扩展</h4><p>&emsp;&emsp;&emsp;&emsp;如何判断类型?<br>&emsp;&emsp;&emsp;&emsp;1.typeof<br>&emsp;&emsp;&emsp;&emsp;2.instanceof<br>&emsp;&emsp;&emsp;&emsp;3.Object.prototype.toString.call()  </p>
<p>&emsp;&emsp;&emsp;&emsp;NaN的类型是number</p>
<h4 id="注意"><a href="#注意" class="headerlink" title="注意"></a><em>注意</em></h4><p>&emsp;&emsp;如下定义并赋值a,那么typeof一下a，返回的是什么类型？</p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-keyword">var</span> a = <span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)&#123;&#125;;<br><span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">typeof</span> a);<br></code></pre></td></tr></table></figure>
<p><img src="../images/function.png" srcset="/img/loading.gif" lazyload alt="结果"><br>&emsp;&emsp;事实证明返回的是function</p>
<p>&emsp;&emsp;整理一下各个类型的typeof</p>
<figure class="highlight qml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs qml"><span class="hljs-comment">// Numbers</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-number">37</span> === <span class="hljs-string">&#x27;number&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-number">3.14</span> === <span class="hljs-string">&#x27;number&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Math</span>.LN2 === <span class="hljs-string">&#x27;number&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-literal">Infinity</span> === <span class="hljs-string">&#x27;number&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-literal">NaN</span> === <span class="hljs-string">&#x27;number&#x27;</span>; <span class="hljs-comment">// 尽管NaN是&quot;Not-A-Number&quot;的缩写</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Number</span>(<span class="hljs-number">1</span>) === <span class="hljs-string">&#x27;number&#x27;</span>; <span class="hljs-comment">// 但不要使用这种形式!</span><br><br><span class="hljs-comment">// Strings</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-string">&quot;&quot;</span> === <span class="hljs-string">&#x27;string&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-string">&quot;bla&quot;</span> === <span class="hljs-string">&#x27;string&#x27;</span>;<br><span class="hljs-keyword">typeof</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-number">1</span>) === <span class="hljs-string">&#x27;string&#x27;</span>; <span class="hljs-comment">// typeof总是返回一个字符串</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">String</span>(<span class="hljs-string">&quot;abc&quot;</span>) === <span class="hljs-string">&#x27;string&#x27;</span>; <span class="hljs-comment">// 但不要使用这种形式!</span><br><br><span class="hljs-comment">// Booleans</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-literal">true</span> === <span class="hljs-string">&#x27;boolean&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-literal">false</span> === <span class="hljs-string">&#x27;boolean&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">true</span>) === <span class="hljs-string">&#x27;boolean&#x27;</span>; <span class="hljs-comment">// 但不要使用这种形式!</span><br><br><span class="hljs-comment">// Symbols</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Symbol</span>() === <span class="hljs-string">&#x27;symbol&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Symbol</span>(<span class="hljs-string">&#x27;foo&#x27;</span>) === <span class="hljs-string">&#x27;symbol&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Symbol</span>.iterator === <span class="hljs-string">&#x27;symbol&#x27;</span>;<br><br><span class="hljs-comment">// Undefined</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-literal">undefined</span> === <span class="hljs-string">&#x27;undefined&#x27;</span>;<br><span class="hljs-keyword">typeof</span> declaredButUndefinedVariable === <span class="hljs-string">&#x27;undefined&#x27;</span>;<br><span class="hljs-keyword">typeof</span> undeclaredVariable === <span class="hljs-string">&#x27;undefined&#x27;</span>; <br><br><span class="hljs-comment">// Objects</span><br><span class="hljs-title">typeof</span> &#123;<span class="hljs-attribute">a</span>:<span class="hljs-number">1</span>&#125; === <span class="hljs-string">&#x27;object&#x27;</span>;<br><br><span class="hljs-comment">// 使用Array.isArray 或者 Object.prototype.toString.call</span><br><span class="hljs-comment">// 区分数组,普通对象</span><br><span class="hljs-keyword">typeof</span> [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>] === <span class="hljs-string">&#x27;object&#x27;</span>;<br><br><span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>() === <span class="hljs-string">&#x27;object&#x27;</span>;<br><br><span class="hljs-comment">// 下面的容易令人迷惑，不要使用！</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Boolean</span>(<span class="hljs-literal">true</span>) === <span class="hljs-string">&#x27;object&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Number</span>(<span class="hljs-number">1</span>) === <span class="hljs-string">&#x27;object&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">String</span>(<span class="hljs-string">&quot;abc&quot;</span>) === <span class="hljs-string">&#x27;object&#x27;</span>;<br><br><span class="hljs-comment">// 函数</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>&#123;&#125; === <span class="hljs-string">&#x27;function&#x27;</span>;<br><span class="hljs-keyword">typeof</span> class <span class="hljs-title">C</span>&#123;&#125; === <span class="hljs-string">&#x27;function&#x27;</span><br><span class="hljs-keyword">typeof</span> <span class="hljs-built_in">Math</span>.sin === <span class="hljs-string">&#x27;function&#x27;</span>;<br><span class="hljs-keyword">typeof</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>() === <span class="hljs-string">&#x27;function&#x27;</span>;<br></code></pre></td></tr></table></figure>

<hr>
<h3 id="转换类型"><a href="#转换类型" class="headerlink" title="转换类型"></a>转换类型</h3><h4 id="1-显式类型转换"><a href="#1-显式类型转换" class="headerlink" title="1.显式类型转换"></a>1.显式类型转换</h4><p>&emsp;&emsp;调用转换方法，主动转换<br>&emsp;&emsp;a.Number()<br>&emsp;&emsp;b.String()<br>&emsp;&emsp;c.Boolean()</p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//显式类型转换</span><br>  <span class="hljs-keyword">var</span> a = <span class="hljs-string">&#x27;123&#x27;</span>;<br>  <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">typeof</span> <span class="hljs-built_in">Number</span>(a) );<br><br>  <span class="hljs-keyword">var</span> a = <span class="hljs-string">&#x27;hello&#x27;</span>;<br>  <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">typeof</span> <span class="hljs-built_in">Number</span>(a) );   <span class="hljs-comment">//NaN</span><br><br>  <span class="hljs-keyword">var</span> a = <span class="hljs-literal">true</span>;<br>  <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">Number</span>(a) );  <span class="hljs-comment">// true -&gt; 1  , false -&gt; 0</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-number">123</span>;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">typeof</span> String(a) );   <span class="hljs-comment">// &#x27;123&#x27;</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-literal">true</span>;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( String(a) );   <span class="hljs-comment">// &#x27;true&#x27;</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-string">&#x27;&#x27;</span>;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">Boolean</span>(a) );   <span class="hljs-comment">//只要字符串有内容就转成true，空字符串转成false</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-number">0</span>;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">Boolean</span>(a) );   <span class="hljs-comment">//只要数字不为0，就转成true，0会转成false</span><br></code></pre></td></tr></table></figure>
<h4 id="2-隐式类型转换"><a href="#2-隐式类型转换" class="headerlink" title="2.隐式类型转换"></a>2.隐式类型转换</h4><p>&emsp;&emsp;被动转换，由JS程序自动进行转换。<br><strong>&emsp;&emsp;+ - * / == 隐式类型转换</strong><br><strong>&emsp;&emsp;+ 数值 - 负数值</strong></p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//隐式类型转换</span><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-string">&#x27;1&#x27;</span>;<br>   <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;<br><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( a + b );  <span class="hljs-comment">//隐式类型转换  b -&gt; 2 -&gt; &#x27;2&#x27; ，然后在连接a变量</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( a - b );  <span class="hljs-comment">//隐式类型转换  a -&gt; &#x27;1&#x27; -&gt; 1 , 然后在相加b变量</span><br></code></pre></td></tr></table></figure>

<hr>
<h3 id="比较类型"><a href="#比较类型" class="headerlink" title="比较类型"></a>比较类型</h3><p>挑一些重点来说了，就不把知识点一一罗列了，具体可以查看w3cSchool  </p>
<h4 id="和-之间的区别"><a href="#和-之间的区别" class="headerlink" title="== 和 = 之间的区别"></a>== 和 = 之间的区别</h4><p>&emsp;&emsp; ==进行比较，而=进行赋值操作</p>
<h4 id="比较时候的几种情况"><a href="#比较时候的几种情况" class="headerlink" title="比较时候的几种情况"></a>比较时候的几种情况</h4><p><strong>1.当两边都是字符串的情况下</strong><br>&emsp;&emsp;按位进行比较，字符的unicode编码进行比较</p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//两边都是字符串的情况 : 按位进行比较，字符的unicode编码进行比较</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-string">&#x27;a&#x27;</span> &gt;= <span class="hljs-string">&#x27;b&#x27;</span> );<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-string">&#x27;a&#x27;</span>.charCodeAt() );  <span class="hljs-comment">//查看字符对应的unicode编码</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-string">&#x27;5&#x27;</span> &gt;= <span class="hljs-string">&#x27;12&#x27;</span> );   <span class="hljs-comment">// true</span><br></code></pre></td></tr></table></figure>
<p><strong>2.当两边不都是字符串的情况下</strong><br>&emsp;&emsp;直接看如下代码吧</p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//两边不都是字符串的情况 : 把其他类型转成数字类型后，再比较</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">5</span> &gt;= <span class="hljs-string">&#x27;12&#x27;</span> );  <span class="hljs-comment">//  5 &gt;= 12   // false</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">true</span> == <span class="hljs-number">1</span> );   <span class="hljs-comment">// true -&gt; 1  -&gt; 1==1   // true</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">true</span> == <span class="hljs-number">2</span> );   <span class="hljs-comment">// false</span><br></code></pre></td></tr></table></figure>
<p>查看字符对应的unicode编码方法：charCodeAt（）<br><strong>3.特殊类型的比较</strong><br>&emsp;&emsp;null、undefined、NaN的比较<br>&emsp;&emsp;老规矩直接上代码，清晰明了</p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//特殊类型的比较 </span><br>     <span class="hljs-literal">null</span>与<span class="hljs-literal">undefined</span>比较的时候，返回<span class="hljs-literal">true</span>。除了下面三种情况，跟其他任何值比较都是<span class="hljs-literal">false</span><br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">null</span> == <span class="hljs-literal">null</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">undefined</span> == <span class="hljs-literal">undefined</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">null</span> == <span class="hljs-literal">undefined</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">null</span> == <span class="hljs-literal">false</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">null</span> == <span class="hljs-literal">true</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">undefined</span> == <span class="hljs-literal">false</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">undefined</span> == <span class="hljs-literal">true</span> );<br><br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">NaN</span> == <span class="hljs-literal">NaN</span> );  <span class="hljs-comment">//false</span><br>     <span class="hljs-comment">//ES6 :  Object.is() : 修正一些判断的</span><br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( Object.is(<span class="hljs-literal">NaN</span> , <span class="hljs-literal">NaN</span>) );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( +<span class="hljs-number">0</span> == <span class="hljs-number">-0</span> );<br>     <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( Object.is(+<span class="hljs-number">0</span> , <span class="hljs-number">-0</span>) );<br></code></pre></td></tr></table></figure>

<p><em>其中 <code>Object.is（）</code>是ES6中为了修正历史遗留问题而推出的。</em></p>
<hr>
<h3 id="JS运算符（五大类）"><a href="#JS运算符（五大类）" class="headerlink" title="JS运算符（五大类）"></a>JS运算符（五大类）</h3><p>因为运算符基本上不需要语言赘述，故直接扔上图和代码</p>
<h4 id="1-算术运算符（10种）"><a href="#1-算术运算符（10种）" class="headerlink" title="1.算术运算符（10种）"></a>1.算术运算符（10种）</h4><p><img src="../images/3%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6.png" srcset="/img/loading.gif" lazyload alt="算术运算符"></p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//算术运算符(10种)</span><br>   <span class="hljs-comment">// + - / * %</span><br>   <span class="hljs-comment">// ++  --</span><br>   <span class="hljs-comment">// +   -</span><br>   <span class="hljs-comment">// **</span><br><br>   <span class="hljs-comment">//4%7 -&gt; 4  当被除数小于除数的时候，余数就是被除数自身</span><br><br>   <span class="hljs-comment">//123秒</span><br>   <span class="hljs-comment">//123%60  , 转换后剩余的秒数</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br>   a++;<br>   ++a;<br><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( a++ );   <span class="hljs-comment">// 先返回a，再对a+1操作</span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( ++a );    <span class="hljs-comment">// 先对a+1操作，然后再返回a</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br>   a++;<br>   ++a;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(a)<br>   <span class="hljs-comment">//+ 数值  -负数值</span><br><br>   <span class="hljs-keyword">var</span> a = <span class="hljs-string">&#x27;123&#x27;</span>;<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-built_in">typeof</span> +a );<br><br>   <span class="hljs-comment">//指数运算符 , 从右向左计算  (ES6)  </span><br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">2</span> ** <span class="hljs-number">2</span> ** <span class="hljs-number">3</span> );<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">2</span> * <span class="hljs-number">2</span> * <span class="hljs-number">2</span> );<br>   <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( Math.<span class="hljs-built_in">pow</span>(<span class="hljs-number">2</span>,<span class="hljs-number">5</span>) );<br></code></pre></td></tr></table></figure>
<h4 id="2-赋值运算符（简单、复合）"><a href="#2-赋值运算符（简单、复合）" class="headerlink" title="2.赋值运算符（简单、复合）"></a>2.赋值运算符（简单、复合）</h4><figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//赋值运算符(简单与复合)</span><br><br>      <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br>      a = a + <span class="hljs-number">2</span>;   <span class="hljs-comment">//简单的赋值运算符</span><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(a);<br><br>      <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br>      a += <span class="hljs-number">2</span>;   <span class="hljs-comment">//复合的赋值运算符</span><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(a);<br><br>      <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br>      <span class="hljs-keyword">var</span> b = <span class="hljs-number">2</span>;<br>      a = b + <span class="hljs-number">3</span>;<br><br>      a++;<br>      a += <span class="hljs-number">1</span>;<br><br>      <span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;<br><br>      a = (a/=<span class="hljs-number">2</span>) + a;<br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>(a);<br><br>      <span class="hljs-comment">//(1 + 2) * 3</span><br></code></pre></td></tr></table></figure>
<h4 id="3-比较运算符（8种）"><a href="#3-比较运算符（8种）" class="headerlink" title="3.比较运算符（8种）"></a>3.比较运算符（8种）</h4><p><img src="../images/4%E6%AF%94%E8%BE%83%E8%BF%90%E7%AE%97%E7%AC%A6.png" srcset="/img/loading.gif" lazyload alt="比较运算符"></p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//比较运算符(8种)</span><br><br>      <span class="hljs-comment">//== === !=  !==</span><br><br>      <span class="hljs-comment">//===表示严格相等，值和类型都要相等，才相等</span><br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">2</span> === <span class="hljs-string">&#x27;2&#x27;</span> );<br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">2</span> != <span class="hljs-number">3</span> );<br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">2</span> !== <span class="hljs-string">&#x27;2&#x27;</span> );<br></code></pre></td></tr></table></figure>
<h4 id="4-逻辑运算符"><a href="#4-逻辑运算符" class="headerlink" title="4.逻辑运算符"></a>4.逻辑运算符</h4><figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//逻辑运算符 : &amp;&amp;(与) ||(或) !(非)</span><br><br>      <span class="hljs-comment">//&amp;&amp; : 逻辑两边都为真，结果才为真，逻辑两边有一边不为真，结果就为假。</span><br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">1</span> &lt; <span class="hljs-number">2</span> &amp;&amp; <span class="hljs-number">5</span> &gt; <span class="hljs-number">4</span> );<br><br>      <span class="hljs-comment">//|| : 逻辑两边有一边为真，结果就为真，逻辑两边都为假，结果才为假。</span><br><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">1</span> &gt; <span class="hljs-number">2</span> || <span class="hljs-number">5</span> &lt; <span class="hljs-number">4</span> );<br><br>      <span class="hljs-comment">//! : 逻辑的取反，真的就是变成假的，假的就会变成真的</span><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( !(<span class="hljs-number">1</span> &gt; <span class="hljs-number">2</span>) );<br><br>      <span class="hljs-keyword">var</span> 艺术生 = <span class="hljs-string">&#x27;小明&#x27;</span>;<br>      <span class="hljs-keyword">var</span> 高考成绩 = <span class="hljs-number">300</span>;<br>      <span class="hljs-keyword">var</span> 艺考成绩 = <span class="hljs-number">200</span>;<br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( 艺术生 , 高考成绩&gt;<span class="hljs-number">200</span> &amp;&amp; 艺考成绩&gt;<span class="hljs-number">100</span> );<br><br>      <span class="hljs-keyword">var</span> <span class="hljs-built_in">number</span> = <span class="hljs-number">70</span>;<br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">3</span> &lt; <span class="hljs-built_in">number</span> &lt; <span class="hljs-number">10</span> );  <span class="hljs-comment">//✖</span><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-number">3</span> &lt; <span class="hljs-built_in">number</span> &amp;&amp; <span class="hljs-built_in">number</span> &lt; <span class="hljs-number">10</span> );  <span class="hljs-comment">//✔</span><br></code></pre></td></tr></table></figure>

<h4 id="5-条件运算符"><a href="#5-条件运算符" class="headerlink" title="5.条件运算符"></a>5.条件运算符</h4><p>三目运算符：<code>条件？输出1：输出2</code></p>
<figure class="highlight arcade"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs arcade"><span class="hljs-comment">//三元运算，三目运算  ? :</span><br>      <span class="hljs-comment">//当条件为真，就返回问号后面的内容，当条件为假，就返回冒号后面的内容</span><br>      <span class="hljs-comment">//执行顺序从右向左</span><br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">false</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span> );<br>      <span class="hljs-built_in">console</span>.<span class="hljs-built_in">log</span>( <span class="hljs-literal">false</span> ? <span class="hljs-number">1</span> : <span class="hljs-number">2</span> ? <span class="hljs-number">3</span> : <span class="hljs-number">4</span> );<br><br></code></pre></td></tr></table></figure>

<hr>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/study/" class="category-chain-item">study</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaScript/">#JavaScript</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>初入JS（二）</div>
      <div>https://moewang0321.github.io/2019/08/05/2019-08-06-初入JS（二）/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Moe Wang</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2019年8月5日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2019/08/06/2019-08-06-DOM/" title="DOM">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">DOM</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2019/08/05/2019-08-05-%E5%88%9D%E5%85%A5JS%EF%BC%88%E4%B8%80%EF%BC%89/" title="初入JS（一）">
                        <span class="hidden-mobile">初入JS（一）</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
    <div id="giscus" class="giscus"></div>
    <script type="text/javascript">
      Fluid.utils.loadComments('#giscus', function() {
        var options = {"repo":"moewang0321/moewang0321.github.io","repo-id":"MDEwOlJlcG9zaXRvcnkyMDEyNDI0NTY=","category":"Show and tell","category-id":"DIC_kwDOC_63WM4CUMsH","theme-light":"light_protanopia","theme-dark":"dark_dimmed","mapping":"pathname","reactions-enabled":1,"emit-metadata":1,"input-position":"top","loading":"lazy","lang":"zh-CN"};
        var attributes = {};
        for (let option in options) {
          if (!option.startsWith('theme-')) {
            var key = option.startsWith('data-') ? option : 'data-' + option;
            attributes[key] = options[option];
          }
        }
        var light = 'light_protanopia';
        var dark = 'dark_dimmed';
        window.GiscusThemeLight = light;
        window.GiscusThemeDark = dark;
        attributes['data-theme'] = document.documentElement.getAttribute('data-user-color-scheme') === 'dark' ? dark : light;
        for (let attribute in attributes) {
          var value = attributes[attribute];
          if (value === undefined || value === null || value === '') {
            delete attributes[attribute];
          }
        }
        var s = document.createElement('script');
        s.setAttribute('src', 'https://giscus.app/client.js');
        s.setAttribute('crossorigin', 'anonymous');
        for (let attribute in attributes) {
          s.setAttribute(attribute, attributes[attribute]);
        }
        var ss = document.getElementsByTagName('script');
        var e = ss.length > 0 ? ss[ss.length - 1] : document.head || document.documentElement;
        e.parentNode.insertBefore(s, e.nextSibling);
      });
    </script>
    <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
